Loading...
 

CX_FORMULA - Formulas

CX_FORMULA

Class hierarchy
Description:

Calculation rules, which do not exist as part of a program but as data generated and managed by the user, are represented in the ClassiX® system by objects of class CX_FORMULA.
A formula object contains an arithmetic expression in the external, human readable form and at the same time an internal representation, which allows a very fast evaluation of the expressions.
The result of the evaluation of a formula can be any object (a numerical value, a truth value, date, string, etc...).

The elements of a formula are operands, operators, InstantView® macros and function calls. Operands are variables or constants.

Note: The operands are always objects. The operations allowed in a formula call corresponding virtual functions of the operands, and thus the object determines the semantics of the operators.

The syntax of formula expressions corresponds to the syntax for describing arithmetic expressions in BASIC, FORTRAN and other common (procedural) programming languages. Terms can be combined in parentheses to influence the order of operations. The complete grammar is documented here in EBNF notation.
Several function parameters are separated by commas. Individual expressions which are to be evaluated independently of each other must be separated by semicolon (this is useful for assignments with :=).
In the formula expression, comments may be placed in the usual C++ form, i.e. at any position with /* ... */ and at the end with //

Variables and external functions refer to objects that have not yet been specified. Only when the formula is evaluated are these operands assigned to data fields or methods of specific objects and thus their value determined. For this purpose, objects are registered in the ClassiX® system(PlugSpace), and thus a current context is created through which the variables of the formula receive a concrete meaning(example).

Examples
Formula Description Elements
0.5 * (x + y) half the sum of x and y x and y are variables, 0.5 a constant
x < y & x >= 2 If x is smaller than y and larger than "2", the result is the truth value TRUE, otherwise FALSE x and y are variables, 2 a constant
Previous(::Day(24,12),6)
Calculates the 4th Advent of a year determined by an object CX_DATE in the PlugSpace Previous is an internal function, Day is an external function, 6, 12 and 24 are constants
more examples you can find here!
Display on screen

A surface object of the type String is used to display objects of this class. The following figure shows an example (program code):

List of methods (MDI)
Function MA* Parameters Return Brief description
Amount OBJECT Evaluate the formula Return the value of the result object
Evaluate OBJECT Evaluate the formula
Evaluate1 OBJECT Evaluation of the formula, unbound variable leads to error
Evaluate2 OBJECT Evaluation of the formula, for unbound variables the result is 0.0 (CX_NUMERIC)
Evaluate3 OBJECT Evaluation of the formula, unbound variables are queried with SendMsg / Waitoninput, if no InstantView® message is logged in: Error
Evaluate4 OBJECT Evaluation of the formula, for unbound variables an object corresponding to the type with value zero is included in the calculation.
EvaluateWeak OBJECT Evaluate the formula condition, as in the Evaluate1Errors are written to a CX_VESSEL object
GetInputAccessPaths
233188
VECTOR&lmt;STRING>Returns all access paths of this formula
GetInputVarNames (OBJECT) VECTOR&lmt;STRING> returns the names of all variables required for the calculation of the formula, if a container object is specified, the corresponding dynamic data fields are created in this object
RawFormula STRING Formula in string form
SetMessage (INTEGER) Log in InstantView® message (for Evaluate3)
ShowIPN STRING Displaying the formula in the IP notation
XMLExport STRING Formula in XML (local character set) form
XML exportUTF8 STRING Formula in the XML form (UTF-8)
Add CX_AMOUNT CX_AMOUNT Operator + as function
AddAssign CX_AMOUNT Operator += as function
AmountWeak CX_AMOUNT
Car format INTEGER, INTEGER CX_AMOUNT Returns a formatted object according to the given number of digits before and after the decimal point (only with CX_VALUE, otherwise the object itself).
DivAssign CX_AMOUNT Operator /= as function
Divide CX_AMOUNT CX_AMOUNT Operator / as function
MulAssign CX_AMOUNT Operator *= as function
Multiply CX_AMOUNT CX_AMOUNT Operator * as function
SubAssign CX_AMOUNT Operator -= as function
Subtract CX_AMOUNT CX_AMOUNT Operator - as a function

* MA = Member Access Function

Special functions within a formula expression
Function Parameters Return Brief description
available (OBJECT) OBJECT tests whether the variable specified as a parameter (i.e. a dynamic data field or an access expression) is bound In contrast to has(...) the variable is loosely bound (the normal case).
get (OBJECT) OBJECT calls for the variable to be closely linked.
has (OBJECT) OBJECT tests whether the variable specified as a parameter (i.e. a dynamic data field or an access expression) is bound, whereby the variable is bound closely (see function get)
inherited (OBJECT, OBJECT) OBJECT tests whether the object designated with variable is derived from the class designated with the second parameter. The name of a class can be specified as a parameter (type constant)
type (OBJECT) OBJECT returns the type of a variable. The result can be compared with a type constant.
var (OBJECT) OBJECT returns the value of an InstantView® variable whose name must be specified as a parameter. var(...) can also be placed at the beginning of an access expression.

Data directory (DDI)
Data field Type Reference class I* Brief description
this CX_FORMULA The formula

* I = Indexable data field

Use in AppsWH
Module Brief description
formula.mod Calculation formula basic module
formulated.mod Calculation formula editing module
formula.mod Calculation formula selection module
formsamp.mod Calculation formula example module
testform.mod Test the formula